package com.qqt.csr.route.assembler;

import com.qqt.csr.common.utils.JsonUtil;
import com.qqt.csr.route.entity.RouteBizRule;
import com.qqt.csr.route.entity.RouteDistributionRule;
import com.qqt.csr.route.vo.req.AddingRouteDistributionRuleReqVO;
import com.qqt.csr.route.vo.req.RouteBizRuleReqVO;
import com.qqt.csr.route.vo.req.UpdatingRouteDistributionRuleReqVO;
import com.qqt.csr.route.vo.resp.RouteBizRuleRespVO;
import com.qqt.csr.route.vo.resp.RouteDistributionRuleDetailRespVO;
import com.qqt.csr.route.vo.resp.RouteQueueOverflowCfgRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper(imports = {JsonUtil.class, RouteQueueOverflowCfgRespVO.class})
public interface RouteDistributionRuleAssembler {
    RouteDistributionRuleAssembler INSTANCE = Mappers.getMapper(RouteDistributionRuleAssembler.class);

    @Mappings({
            @Mapping(target = "queueTimeoutCfg", expression = "java(JsonUtil.toJson(reqVO.getQueueTimeoutCfg()))"),
            @Mapping(target = "routeBizRuleList", ignore = true),
    })
    RouteDistributionRule toRouteDistributionRule(AddingRouteDistributionRuleReqVO reqVO);

    @Mappings({
            @Mapping(target = "queueTimeoutCfg", expression = "java(JsonUtil.toJson(reqVO.getQueueTimeoutCfg()))"),
            @Mapping(target = "routeBizRuleList", ignore = true),
    })
    RouteDistributionRule toRouteDistributionRule(UpdatingRouteDistributionRuleReqVO reqVO);

    @Mappings({
            @Mapping(target = "skillSetIds", expression = "java(JsonUtil.toJson(reqVO.getSkillSetIds()))"),
    })
    RouteBizRule toRouteBizRule(RouteBizRuleReqVO reqVO);

    List<RouteBizRule> toRouteBizRuleList(List<RouteBizRuleReqVO> reqVOList);

    @Mappings({
            @Mapping(target = "queueTimeoutCfg", expression = "java(JsonUtil.toObject(rule.getQueueTimeoutCfg(), RouteQueueOverflowCfgRespVO.class))"),
    })
    RouteDistributionRuleDetailRespVO toRouteDistributionRuleDetailRespVO(RouteDistributionRule rule);

    @Mappings({
            @Mapping(target = "skillSetIds", expression = "java(routeBizRule.getSkillSetIdList())"),
    })
    RouteBizRuleRespVO toRouteBizRuleRespVO(RouteBizRule routeBizRule);
}
